package com.czk.netty.netty.tcp.protocaltcp.practice.test;

import com.czk.netty.netty.tcp.protocaltcp.practice.client.Client;
import com.czk.netty.netty.tcp.protocaltcp.practice.protocol.TransferProtocol;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;

import java.nio.charset.Charset;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/6/8 11:30
 */
public class StartClient {
    public static void main(String[] args) throws InterruptedException {
        Client client = new Client();
        ChannelFuture channel = client.bind();

        // 发送消息
        for (int i = 0; i < 10; i++) {
            String str = "今天杜兰特狂砍32分";
            byte[] content = str.getBytes(Charset.forName("UTF-8"));
            int len = str.getBytes(Charset.forName("UTF-8")).length;
            // 封装对象
            TransferProtocol transferProtocol = new TransferProtocol();
            transferProtocol.setContent(content);
            transferProtocol.setLength(len);
            channel.channel().writeAndFlush(transferProtocol);
        }
    }
}
